<template>
  <div>
    <m-head title="我的团队"></m-head>
    <div class="box">
      <!--<div class="tnav">-->
        <!--<span :class="item===0?'active':''" @click="onToggle(0)">我的团队</span>-->
        <!--<span :class="item===1?'active':''" @click="onToggle(1)">我的推荐人</span>-->
      <!--</div>-->
      <div class="con" v-show="item===0">
        <div class="item" v-for="(item, id) in team" v-bind:key="id">
          <div class="title" @click="onShow(item.id)">
            <img :src="item.avatar" alt="">
            <h3>{{item.nickname}}</h3>
            <span>查看成员></span>
          </div>
          <ul class="subbox clearfix" v-show="item.show&&item.children.length>0">
            <li class="subitem" v-for="(subitem, subid) in item.children" v-bind:key="subid">
              <img :src="subitem.img" alt="">
              <p>{{subitem.name}}</p>
            </li>
          </ul>
        </div>
      </div>
      <div class="con" v-show="item===1">
        <div class="item">
          <div class="title">
            <img :src="recommend.avatar" alt="">
            <h3>{{recommend.nickname}}</h3>
          </div>
        </div>
      </div>
    </div>
    </div>
</template>

<script>
import MHead from './MHeader'
import * as user from '../api/user'
import store from '../utils/store'

export default {
  name: 'account',
  components: {
    'm-head': MHead
  },
  data () {
    return {
      item: 0,
      team: {},
      list: {},
      recommend: {}
    }
  },
  mounted () {
    const userId = store.getters.getUserInfo.id
    this.getMyTeam(userId)
    this.getRecommend()
  },
  methods: {
    getMyTeam (referId) {
      user.getTeam(referId).then(res => {
        this.team = res.data
      })
    },
    getRecommend () {
      user.getRefer().then(res => {
        this.recommend = res.data
      })
    },
    onToggle: function (value) {
      if (this.$data.item !== value) {
        if (value) {
          this.$data.item = 1
        } else {
          this.getMyTeam(0)
          this.$data.item = 0
        }
      }
    },
    onShow: function (id) {
      this.getMyTeam(id)
    }
  },
}
</script>

<style scoped>
  .tnav{
    height: 1.5rem;
    display: flex;
    border-bottom: 1px solid #ddd;
  }
  .tnav span{
    width: 50%;
    display: block;
    background: #eee;
    border-right: 1px solid #eee;
    text-align: center;
    font-size: .48rem;
    color: #333;
    line-height: 1.5rem;
  }
  .tnav span.active{
    background: #fff;
  }
  .con{
    border-top: 10px solid #f5f5f5;
  }
  .item{
    border-bottom: 10px solid #f5f5f5;
  }
  .title{
    display: flex;
    align-items: center;
    height: 1.4rem;
    padding: 0 .3rem;
  }
  .title img{
    width: 1rem;
    height: 1rem;
    -webkit-border-radius: 6px;
    -moz-border-radius: 6px;
    border-radius: 6px;
    margin-right: .3rem;
  }
  .title h3{
    font-size: .42rem;
    color: #333;
    flex-grow: 1;
  }
  .subbox{
    padding-top: .3rem;
    border-top: 1px solid #ddd;
  }
  .subitem{
    width: 25%;
    text-align: center;
    float: left;
    margin-bottom: .3rem;
  }
  .subitem img{
    width: 2rem;
    height: 2rem;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
  }
</style>
